<template>
	<view class="index_recommend">
		<view v-for="(item,index) in params.list" :key="index">
			<ABlogCard :item="item"></ABlogCard>
		</view>
		<view v-if="params.list.length===0" class="empty_container">
			<u-empty text="当前关注用户暂未发帖" mode="data" width="100%" iconSize="60" textSize="32"></u-empty>
		</view>
	</view>
</template>

<script>
	import {
		getBlogList,
		getBlogFollow
	} from '@/api/forum.js'
	export default {
		watch: {
			'refresh': {
				handler(val) {
					if (val) {
						this.init()
					}
				}
			}
		},
		mounted() {
			// 触底加载
			this.init()
			uni.$on('onBottom', () => {
				this.getList(this.query)
			})
			// 重新获取数据
			uni.$on('reloadlist', () => {
				this.init()
			})
		},
		props: ['refresh'],
		onReachBottom() {
			console.log(1);
		},
		data() {
			return {
				params: {
					list: [],
					total: 0,
				},
				query: {
					lastId: null,
					offset: null,
				}
			}
		},
		methods: {
			init() {
				getBlogFollow().then(res => {
					this.params.list = res.data.list
					this.query.lastId = res.data.minTime
					this.query.offset = res.data.offset
				})
			},
			// 获取帖子数据
			getList({
				lastId,
				offset
			}, flag = true) {
				if (flag) {
					getBlogFollow(lastId, offset).then(res => {
						this.query.lastId = res.data.minTime
						this.query.offset = res.data.offset
						this.params.list = this.params.list.concat(res.data.list)
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.index_recommend {

		// padding: 20rpx;
		.empty_container {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 60vh;

			.u-empty {
				height: 60vh;
			}
		}


	}
</style>